﻿//-------------------------------------------------------------------
//	Copyright (c) 2010-2014  Zhirnov Andrey
//	This file is part of the "UX Standard Lib" project.
//	See copyright notice in "UX_Logger.h".
//-------------------------------------------------------------------

#include "COutputMessages.h"

namespace UX_STL
{
namespace UXLogger
{
	
/*
=================================================
	конструктор
=================================================
*/
	COutputMessages::COutputMessages():
		_eFlagFilter(e_log_msg::FILTER_WITH_LINE),
		_eWarningLevel(e_log_msg::LEVEL_ALL)
	{
		SetLevel( 15 );
	}
	
/*
=================================================
	деструктор
=================================================
*/
	COutputMessages::~COutputMessages()
	{
	}
	
/*
=================================================
	вывести сообщение
=================================================
*/
	void COutputMessages::Write(const char *pMsg, e_log_msg::type eType, const char *pSrcFile, uint uLine)
	{
		if ( (eType & e_log_msg::_LWL_MASK) > _eWarningLevel or
			 EnumNoCmp( eType, _eFlagFilter ) )
		{
			return;
		}
		
		static const char *	s_aMessageTypes[] = {
			"",
			"INFO",
			"DEBUG",
			"SYSTEM",
			"USER",
			"WARNING",
			"ERROR",
			"FATAL ERROR",
			"", "", "", "", "", "", ""
		};

		string	s_msg( pMsg );
		uint8	idx	= ( eType & e_log_msg::_LMP_MASK ) >> e_log_msg::_LMP_OFFSET;
		
		if ( EnumCmp( eType, e_log_msg::_LMPX_FILE_LINE ) and pSrcFile != null and uLine != -1 )
			s_msg << "\n\n file: \"" << pSrcFile << "\"\n line: " << uLine;

		s_msg << "\n\nAbort  - close application\nRetry   - break\nIgnore - continue";

		e_msg_button_ret::type	ret = TPlatform::ErrorMsg( s_aMessageTypes[idx], s_msg.cstr(),
														 e_msg_buttons::ABORT_RETRY_IGNORE );

		switch ( ret )
		{
			case e_msg_button_ret::RETRY :	UX_BREAK_POINT();		break;
			case e_msg_button_ret::ABORT :	_hidden_::exit(0);	break;
		};
	}
	
/*
=================================================
	(не используется)
=================================================
*/
	void COutputMessages::NewLine()
	{
	}
	
/*
=================================================
	удалить
=================================================
*/
	void COutputMessages::Free()
	{
		delete this;
	}

//-------------------------------------------------------------------

}	// UXLogger
}	// UX_STL